package net.javlov;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class TransitionModel {

	protected Map<State, Map<State, Double>[]> model;
	protected int numactions;
	
	public TransitionModel(int states, int actions) {
		numactions = actions;
		model = new HashMap<State, Map<State, Double>[]>(states*2, 0.5f);
	}
	
	public void addEntry(State s, Action a, State sprime, double transitionprob) {
		Map<State, Double>[] entry = model.get(s);
		if ( entry == null ) {
			entry = initializeNewEntry();
			model.put(s, entry);
		}
		entry[a.getID()].put(sprime, transitionprob);
	}
	
	protected Map<State, Double>[] initializeNewEntry() {
		Map[] entry = new HashMap[numactions];
		for ( int i = 0; i < numactions; i++ )
			entry[i] = new HashMap<State, Double>(16, 0.5f);
		return entry;
	}
}
